package com.cn.yugan.Engine.Http;

import android.content.Context;
import android.content.SharedPreferences;

import com.cn.yugan.Cons.ArticleConstants;
import com.cn.yugan.Utils.LogUtils;
import com.cn.yugan.Utils.StringConv;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;

/**
 * Created by Rover on 2016/10/11 .
 * Email 357319517@qq.com
 * 获取列表文件
 */
public class GetList {
    /**
     * 获取文章列表
     *
     * @param context
     * @param url
     * @param type
     * @param orderby
     * @param page
     * @param responseHandler
     */
    public static void ArticleListAsyncHttpClient(Context context, String url, String type, String orderby, int page, ResponseHandlerInterface responseHandler) {
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient(true, 80, 443);
        asyncHttpClient.addHeader("Cookie", AddReqCookie.getNormalheader(context));
        RequestParams params = new RequestParams();
        params.put("type", type);
        params.put("orderby", orderby);
        params.put("limit[0]", page);
        params.put("limit[1]", 20);
        asyncHttpClient.post(context, url, params, responseHandler);
    }

    /**
     * 获取评论列表
     *
     * @param context
     * @param url
     * @param aid
     * @param page
     * @param responseHandler
     */
    public static void CommentListAsyncHttpClient(Context context, String url, String aid, int page, ResponseHandlerInterface responseHandler) {
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient(true, 80, 443);
        asyncHttpClient.addHeader("Cookie", AddReqCookie.getNormalheader(context));
        RequestParams params = new RequestParams();
        params.put("aid", aid);
        params.put("page", page);
        params.put("every", 20);
        asyncHttpClient.post(context, url, params, responseHandler);
    }

    /**
     * 获取收藏列表
     *
     * @param context
     * @param url
     * @param responseHandler
     */
    public static void FavoriteListAsyncHttpClient(Context context, String url, ResponseHandlerInterface responseHandler) {
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient(true, 80, 443);
        asyncHttpClient.addHeader("Cookie", AddReqCookie.getNormalheader(context));
        RequestParams params = new RequestParams();
        params.put("action", "all");
        asyncHttpClient.post(context, url, params, responseHandler);
    }

    /**
     * 获取投稿列表
     *
     * @param context
     * @param url
     * @param responseHandler
     */
    public static void OriListAsyncHttpClient(Context context, String url, ResponseHandlerInterface responseHandler) {
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient(true, 80, 443);
        asyncHttpClient.addHeader("Cookie", AddReqCookie.getNormalheader(context));
        RequestParams params = new RequestParams();
        asyncHttpClient.post(context, url, params, responseHandler);
    }

    /**
     * 获取关注列表
     *
     * @param context
     * @param url
     * @param responseHandler
     */
    public static void VoteListAsyncHttpClient(Context context, String url, int page, ResponseHandlerInterface responseHandler) {
        SharedPreferences sp = context.getSharedPreferences("Session", context.MODE_PRIVATE);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient(true, 80, 443);
        asyncHttpClient.addHeader("Cookie", AddReqCookie.getNormalheader(context));
        RequestParams params = new RequestParams();
        LogUtils.d(sp.getString("uid",""));
       
        params.put("uid", StringConv.sp2normal(sp.getString("uid", "=0;")));
        params.put("names[0]", "vote");
        params.put("names[1][0]", "voteList");
        params.put("names[1][1][0]", page);
        params.put("names[1][1][1]", 20);
        asyncHttpClient.post(context, url, params, responseHandler);
    }
}
